/*
 * @Description: 出口许可证管理DS
 * @Version: 1.0
 * @Autor: c-jack.qian
 * @Date: 2020-12-28 20:03:25
 * @LastEditors: c-jack.qian
 * @LastEditTime: 2021-04-25 14:47:03
 */
import { DataSetSelection, FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import commonConfigStore from '@common/config/commonConfig';
import intl from 'utils/intl';
import { DataSet } from 'choerodon-ui/pro/lib';
const O2_OM = process.env.NODE_ENV === 'development' ? '/o2om-c' : commonConfigStore.O2_OM;

// 订单类型
const regionsOptions = new DataSet({
    selection: 'single' as DataSetSelection,
    autoQuery: true,
    paging: false,
    transport: {
        read: config => {
            return {
                ...config,
                url: `/hitf/v1/dji-external-interface/get-regions`,
                method: 'post',
                transformResponse: value => {
                    const reqData = JSON.parse(value);
                  console.log(reqData);
                  
                    return reqData.data;
                },
            };
        },
    },
});

const exportLicenseManagementDS = () => ({
    autoQuery: true,
    selection: 'multiple',
    primaryKey: 'id',
    transport: {
        read: config => {
            return {
                ...config,
                url: `${O2_OM}/v1/export-licenses`,
                method: 'get',
            };
        },
        destroy: config => {
            return {
                ...config,
                url: `${O2_OM}/v1/export-licenses`,
                method: 'delete',
            };
        },
    },
    fields: [
        {
            name: 'countryName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.countryName').d('国家'),
        },
        {
            name: 'customerName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.agentName').d('代理商名称'),
            required: true,
        },
        {
            name: 'contractNumber',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.contractNumber').d('合同号'),
            required: true,
        },
        {
            name: 'applicationNumber',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.applicationNumber').d('申请单号'),
        },
        {
            name: 'originalApplicationNumber',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.originalApplicationNumber').d('原申请单号'),
        },
        {
            name: 'exportLicense',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.exportLicense').d('许可证张数'),
        },
        {
            name: 'productName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.productNameStyle').d('机型'),
        },
        {
            name: 'licenseQuantity',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.licenseQuantity').d('证书数量'),
            required: true,
        },
        {
            name: 'typeOfShipping',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.typeOfShipping').d('运输方式'),
            required: true,
        },
        {
            name: 'usedQuantity',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.usedQuantity').d('证书使用数量'),
        },
        {
            name: 'deliveryQuantity',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.deliveryQuantity').d('实际出货数量'),
        },
        {
            name: 'availableQuantity',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.availableQuantity').d('出口额度'),
        },
        {
            name: 'effectiveDateTo',
            type: FieldType.dateTime,
            label: intl.get('dji.otc.om.view.field.effectiveDate').d('有效期'),
            required: true,
        },
        {
            name: 'exportLicenseStatus',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.checkRuleStatusCode').d('状态'),
            required: true,
        },
        {
            name: 'deliveryDate',
            type: FieldType.dateTime,
            label: intl.get('dji.otc.om.view.field.deliveryDate').d('出货时间'),
        },
        {
            name: 'deliveryNumber',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.deliveryNumber').d('出货单号'),
        },
        {
            name: 'memo',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.memo').d('备注'),
        },
        {
            name: 'productName123',
            type: FieldType.number,
            label: intl.get('dji.otc.om.view.field.takeQuantity').d('占用数量'),
        },
    ],
    queryFields: [
        // {
        //     label: intl.get('dji.otc.om.view.field.isCreditApplied').d('组别'),
        //     name: 'businessGroupCode',
        //     type: FieldType.string,
        //     lookupCode: 'DJICM_GROUP',
        // },
        {
            label: intl.get('dji.otc.om.view.field.countryName').d('国家'),
            name: 'countryId',
            type: FieldType.number,
            options: regionsOptions,
            valueField: 'regionId',
            textField: 'regName',
        },
        {
            name: 'customerName',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.agentName').d('代理商'),
        },
    ],
});


export { exportLicenseManagementDS };
